package com.cdelink.xzgy.ftp.common.page;

import java.util.List;

public class PageResponse<T> extends Page {
    /**
     * 总条数
     */
    private Long totalElements = 0L;
    /**
     * 总页数
     */
    private Long pages = 0L;
    /**
     * 数据实体
     */
    private List<T> data;

    public PageResponse() {
    }

    public PageResponse(Integer pageIndex, Integer pageSize) {
        super(pageIndex, pageSize);
    }

    /**
     * 获取当前页
     */
    private void calculatePages() {
        Long totalElements = getTotalElements();
        if (totalElements % pageSize == 0) {
            pages = totalElements / pageSize;
        } else {
            pages = totalElements / pages + 1;
        }
    }

    public Long getTotalElements() {
        if (totalElements != null) {
            return totalElements;
        }
        return 0L;
    }

    public void setTotalElements(Long totalElements) {
        this.totalElements = totalElements;
    }

    public Long getPages() {
        return pages;
    }

    public void setPages(Long pages) {
        this.pages = pages;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    @Override
    public void setPageSize(Integer pageSize) {
        super.setPageSize(pageSize);
        calculatePages();
    }
}
